package cn.royan.fl.utils
{
	import com.hurlant.crypto.prng.Random;
	import flash.display.Sprite;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;
	import flash.net.navigateToURL;
	import flash.utils.ByteArray;

	import com.hurlant.crypto.symmetric.ICipher;
	import com.hurlant.crypto.symmetric.IVMode;
	import com.hurlant.crypto.symmetric.IMode;
	import com.hurlant.crypto.symmetric.NullPad;
	import com.hurlant.crypto.symmetric.PKCS5;
	import com.hurlant.crypto.symmetric.IPad;
	import com.hurlant.util.Base64;
	import com.hurlant.util.Hex;
	import com.hurlant.crypto.Crypto;
 
	public class CryptoCode
	{
		private static var type:String='simple-des-ecb';
		public static var key:String = "iamlock0";
 
		public static function encrypt( txt:String = '' ):String
		{
			var data:ByteArray = Hex.toArray( Hex.fromString( txt ) );

			var pad:IPad = new PKCS5();
			var mode:ICipher = Crypto.getCipher( type, Hex.toArray( Hex.fromString( key ) ), pad );
				pad.setBlockSize( mode.getBlockSize() );
				mode.encrypt( data );
			return Base64.encodeByteArray( data );
		}
		
		public static function decrypt( txt:String = '' ):String
		{
			var data:ByteArray = Base64.decodeToByteArray( txt );
			var pad:IPad = new PKCS5();
			var mode:ICipher = Crypto.getCipher( type, Hex.toArray( Hex.fromString( key ) ), pad );
				pad.setBlockSize( mode.getBlockSize() );
				mode.decrypt( data );
			return Hex.toString( Hex.fromArray( data ) );
		}
		
		private function gen( v:int ):String {
			var r:Random = new Random();
			var b:ByteArray = new ByteArray();
			r.nextBytes( b, v/8 );
			return Hex.fromArray( b );
		}
	}
}